package com.ruoyi.vstac.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.vstac.domain.VstacWork;
import com.ruoyi.vstac.service.IVstacWorkService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 作品 Controller
 * 
 * @author ruoyi
 * @date 2024-06-11
 */
@RestController
@RequestMapping("/vstac/work")
public class VstacWorkController extends BaseController
{
    @Autowired
    private IVstacWorkService vstacWorkService;

    /**
     * 查询作品 列表
     */
    @PreAuthorize("@ss.hasPermi('vstac:work:list')")
    @GetMapping("/list")
    public TableDataInfo list(VstacWork vstacWork)
    {
        startPage();
        List<VstacWork> list = vstacWorkService.selectVstacWorkList(vstacWork);
        return getDataTable(list);
    }

    /**
     * 导出作品 列表
     */
    @PreAuthorize("@ss.hasPermi('vstac:work:export')")
    @Log(title = "作品 ", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, VstacWork vstacWork)
    {
        List<VstacWork> list = vstacWorkService.selectVstacWorkList(vstacWork);
        ExcelUtil<VstacWork> util = new ExcelUtil<VstacWork>(VstacWork.class);
        util.exportExcel(response, list, "作品 数据");
    }

    /**
     * 获取作品 详细信息
     */
    @PreAuthorize("@ss.hasPermi('vstac:work:query')")
    @GetMapping(value = "/{workId}")
    public AjaxResult getInfo(@PathVariable("workId") Long workId)
    {
        return success(vstacWorkService.selectVstacWorkByWorkId(workId));
    }

    /**
     * 新增作品 
     */
    @PreAuthorize("@ss.hasPermi('vstac:work:add')")
    @Log(title = "作品 ", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody VstacWork vstacWork)
    {
        return toAjax(vstacWorkService.insertVstacWork(vstacWork));
    }

    /**
     * 修改作品 
     */
    @PreAuthorize("@ss.hasPermi('vstac:work:edit')")
    @Log(title = "作品 ", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody VstacWork vstacWork)
    {
        return toAjax(vstacWorkService.updateVstacWork(vstacWork));
    }

    /**
     * 删除作品 
     */
    @PreAuthorize("@ss.hasPermi('vstac:work:remove')")
    @Log(title = "作品 ", businessType = BusinessType.DELETE)
	@DeleteMapping("/{workIds}")
    public AjaxResult remove(@PathVariable Long[] workIds)
    {
        return toAjax(vstacWorkService.deleteVstacWorkByWorkIds(workIds));
    }
}
